package com.biancheng.biancheng.L2;

public class 平衡二叉树 {

    public boolean isBalanced(TreeNode root) {
        if(root==null) return true;
        if(Math.abs(getHeigth(root.left)-getHeigth(root.right))<=1){
            return isBalanced(root.left) && isBalanced(root.right);
        }
        return false;
    }
    public int getHeigth(TreeNode root){
        if(root==null) return 0;
        return Math.max(getHeigth(root.left),getHeigth(root.right))+1;
    }

}
